package com.msb.servlet;

import com.msb.entity.Cpi;
import com.msb.mapper.Mapper;
import com.msb.unitil.DBUnitil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

/**
 * @version : 1.0
 * @Author: yangmingsong
 * @Date: 2021/2/7-02-07-23:26
 * @Description: demon
 */
@WebServlet(urlPatterns = "/Doshow")
public class Doshow extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1、设置字符编码
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");

        //4、mybaties框架调用方法
        Mapper mapper = DBUnitil.getsqlsession().getMapper(Mapper.class);

        List<Cpi> rs = mapper.selectAll();
        DBUnitil.getsqlsession().close();
        for(Cpi cpi:rs){
            System.out.println(cpi.getUnit());
        }
        //5、处理返回结果
        if(rs == null){
            //重定向，实现页面跳转
            response.sendRedirect("home.jsp");
        }else{
            //提示信息
            request.setAttribute("list",rs);
            //重定向实现页面跳转
            request.getRequestDispatcher("llist.jsp").forward(request,response);

        }
    }
}
